home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / qprt_jf.com / QPRINTF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-04  |  3.6 KB  |  104 lines

  1. /****************************************************************************
  2.  
  3.   QPRINTF.C  -  Quick screen output  -  Jeff R. Fontanesi,  7/4/89
  4.  
  5.   The routines included here, qprintf and qputch, are fast screen
  6.   output routines.  They write directly to the video RAM using
  7.   Turbo C's pokeb function.
  8.  
  9.   Before using these routines, use qp_init to determine which type
  10.   of adapter the system has.  This routine sets the global variable
  11.   _vidseg to 0xb000 for monochrome or 0xb800 for CGA or other.
  12.   This is necessary for execution of qprintf and qputch.
  13.  
  14.   The qprintf and qputch routines use nearly the same format as printf
  15.   and putch respectively and behave similarly.  The differences are:
  16.  
  17.   * qprintf and qputch allow you to specify the row, column and
  18.     attribute of the string or character to be displayed.  The ranges
  19.     of the row and column parameters are 1..25 and 1..80 respectively.
  20.  
  21.   * qprintf and qputch do not change the cursor position.
  22.  
  23.   * qp_init must be invoked once before qprintf and qputch.  Side
  24.     effects may result if this is not done.
  25.  
  26.   * Using the escape sequences, \a, \b, \f, \n, \r, \t or \v may
  27.     produce unexpected results because qprintf and qputch write
  28.     directly to video RAM and do not translate these codes.
  29.  
  30.   * You should not try to print outside the screen boundaries or print
  31.     strings longer than 80 characters.  Doing so can overwrite
  32.     unexpected areas of memory and may produce side effects.  No
  33.     boundary checking is done in these routines.
  34.  
  35.   Syntax of qprintf:
  36.  
  37.   void qprintf(int col, int row, int attr, const char *format[,argument,...]);
  38.  
  39.     int col  - the column or x coordinate
  40.     int row  - the row or y coordinate
  41.     int attr - the attribute (foreground and background color)
  42.     const char *format[argument,...] - the standard C format string and
  43.                                        arguments used by printf
  44.  
  45.   Syntax of qputch:
  46.  
  47.   void qputch(int col, int row, int attr, char ch);
  48.  
  49.     int col  - the column or x coordinate
  50.     int row  - the row or y coordinate
  51.     int attr - the attribute (foreground and background color)
  52.     char ch  - the character to be displayed
  53.  
  54.  
  55.   These routines are free for any use.  I only ask that if you use them
  56.   or find errors, please let me know.  I can be reached as:
  57.  
  58.   Jeff R. Fontanesi
  59.   CompuServe - 74017,1650
  60.   Genie      - FONTJR
  61.   Various Southern California BBS's
  62.  
  63. ****************************************************************************/
  64.  
  65. #include <stdarg.h>
  66. #include <stdio.h>
  67.  
  68. unsigned int _vidseg;
  69.  
  70. void qp_init(void)
  71. {
  72.   const long vidmode = 0x00449lu;                    /* video mode address */
  73.  
  74.   if (*((char far*) vidmode) == 7)                   /* if video mode is 7 */
  75.     _vidseg = 0xb000u;                               /* then monochrome */
  76.   else
  77.     _vidseg = 0xb800u;                               /* else, color */
  78. }
  79.  
  80. void qputch(int col, int row, int attr, char ch)
  81. {
  82.   register int vidofs;
  83.  
  84.   pokeb(_vidseg, vidofs = 160*row+2*col-162, ch);      /* poke the char */
  85.   pokeb(_vidseg, ++vidofs, attr);                      /* poke the attr */
  86. }
  87.  
  88. void qprintf(int col, int row, int attr, char *str, ...)
  89. {
  90.   register int i, x;
  91.   int vidofs;
  92.   char vstr[90];
  93.   va_list vl;
  94.  
  95.   va_start(vl,str);                                  /* get the arguments */
  96.   vsprintf(vstr,str,vl);
  97.   va_end(vl);
  98.   for (i = 0, x = col; vstr[i]; i++, x++)
  99.   {
  100.     pokeb(_vidseg, vidofs = 160*row+2*x-162, vstr[i]);    /* poke the char */
  101.     pokeb(_vidseg, ++vidofs, attr);                       /* poke the attr */
  102.   }
  103. }
  104.